"""
    遍历文件夹下(包括子文件夹)的所有文件
"""
import os


def traversal_suffix(url, suffix=''):
    """
    遍历文件夹下的所有文件
    :param url: 要遍历的路径
    :param suffix: 后缀过滤, 不过滤则不传该参数
    :return: 遍历的所有文件的绝对路径
    """
    all_full_paths = []
    if url == '' or url is None or not os.path.isdir(url):
        return
    for file_path, subdir, filename_list in os.walk(url):
        for file_name in filename_list:
            full_path = os.path.join(file_path, file_name)
            if full_path.endswith(suffix) or suffix == '' or suffix is None:
                all_full_paths.append(full_path)

    return all_full_paths


def remove_file(full_path):
    """
    删除文件
    :param full_path:
    :return:
    """
    os.remove(full_path)


def example_del_all_jars():
    for a_path in traversal_suffix(r'F:\总结git\Notes\Java总结\JavaShuoGG code\test-springMVC', '.jar'):
        print('To remove file:', a_path)
        remove_file(a_path)


if __name__ == "__main__":
    # example_del_all_jars()
    print("ok")
